<template>
  <!-- 添加或修改业务对话框 -->
  <el-dialog :title="title" :visible.sync="open" width="1200px" :close-on-click-modal="false" append-to-body>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="捆包号" prop="bundleNumber">
        <el-input
          type="textarea"
          rows="1"
          style="width: 205px"
          v-model="queryParams.bundleNumber"
          placeholder="请输入捆包号"
          clearable
        />
      </el-form-item>
      <el-form-item label="货物类型" prop="goodsType">
        <el-select v-model="queryParams.goodsType" placeholder="请选择货物类型" clearable>
          <el-option
            v-for="dict in dict.type.goods_type"
            :key="dict.value"
            :label="dict.label"
            :value="dict.label"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="货权客户" prop="goodsRightCustomer">
        <el-select v-model="queryParams.goodsRightCustomer" placeholder="请选择货权客户" clearable filterable>
          <el-option
            v-for="dict in customerOptions"
              :key="dict.customerId"
              :label="dict.customerName"
              :value="dict.customerName"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="合约号" prop="agreementNumber">
        <el-input
          v-model="queryParams.agreementNumber"
          placeholder="请输入合约号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="合同号" prop="contractNumber">
        <el-input
          v-model="queryParams.contractNumber"
          placeholder="请输入合同号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

    </el-form>

    <el-table  :data="goodList" @selection-change="handleSelectionChange" border :height="tableHeight" :row-style="{height:'35px'}" :cell-style="{padding:'0px'}">
      <el-table-column type="selection" width="45" align="center" />
      <el-table-column type="index" prop="" width="55" label="序号" align="center" >
        <template slot-scope="scope">
          <span>{{ scope.$index+1 +(queryParams.pageNum-1)*queryParams.pageSize }}</span>
        </template>
      </el-table-column>

      <!--el-table-column label="货物ID" align="center" prop="goodsId" /-->
      <el-table-column label="捆包号" align="center" prop="bundleNumber" width="180" :show-overflow-tooltip="true" />
      <el-table-column label="货物类型" align="center" prop="goodsType">
        <!--template slot-scope="scope">
          <dict-tag :options="dict.type.goods_type" :value="scope.row.goodsType"/>
        </template-->
      </el-table-column>
      <!--el-table-column label="产地" align="center" prop="producer" /-->
      <el-table-column label="品名" align="center" prop="product" />
      <el-table-column label="规格" align="center" prop="specification" width="110" :show-overflow-tooltip="true" />
      <el-table-column label="材质" align="center" prop="steelGrade" />
      <el-table-column label="重量(吨)" align="center" prop="weight" />
      <el-table-column label="合约号" align="center" prop="agreementNumber" width="110" :show-overflow-tooltip="true" />
      <el-table-column label="合同号" align="center" prop="contractNumber" width="160" :show-overflow-tooltip="true" />
      <el-table-column label="园区信息" align="center" prop="logisticsParkName">
        <!--template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.logisticsParkName"/>
        </template-->
      </el-table-column>
      <el-table-column label="仓位信息" align="center" prop="warehouseLocateName">
        <!--template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.warehouseLocateName"/>
        </template-->
      </el-table-column>
      <el-table-column label="区位信息" align="center" prop="regionLocateName">
        <!--template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.regionLocateName"/>
        </template-->
      </el-table-column>
      <el-table-column label="货位信息" align="center" prop="goodsLocateName">
        <!--template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.goodsLocateName"/>
        </template-->
      </el-table-column>


    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />


    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listGood, getGood, delGood, addGood, updateGood, updateGoodEnterWarehouseNumber } from "@/api/goods/good";
import { listCustomerOption } from "@/api/customs/custom";
import { isNotNull } from "@/utils/validate";

export default {
  name: "addGoodsDialog",
  props: ["refreshGoodsDetail"],
  dicts: ['warehouse_type', 'sys_yes_no', 'settlement_mode', 'price_mode', 'distribute_goods_status', 'goods_type', 'inventory_status', 'check_status'],
  data() {
    return {
      // 定义列表高度
      tableHeight: 360,
      // 定义查询高度
      queryHeight: 200,
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 货物信息表格数据
      goodList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        bundleNumber: null,
        goodsType: null,
        producer: null,
        product: null,
        specification: null,
        steelGrade: null,
        weight: null,
        agreementNumber: null,
        contractNumber: null,
        produceDate: null,
        recordSource: null,
        inventoryStatus: null,
        warehouseType: null,
        logisticsParkName: null,
        warehouseLocateName: null,
        regionLocateName: null,
        goodsLocateName: null,
        layerLocateName: null,
        warehouseTotalLocate: null,
        enterWarehouseNumber: null,
        enterWarehouseCheck: null,
        enterWarehouseCustomer: null,
        enterWarehouseDriver: null,
        enterWarehouseVehicle: null,
        enterWarehousePerson: null,
        enterWarehouseTime: null,
        enterWarehouseConfirmPerson: null,
        enterWarehouseConfirmTime: null,
        exitWarehouseNumber: null,
        exitWarehouseCheck: null,
        exitWarehouseCustomer: null,
        exitWarehouseDriver: null,
        exitWarehouseVehicle: null,
        exitWarehousePerson: null,
        exitWarehouseTime: null,
        exitWarehouseConfirmPerson: null,
        exitWarehouseConfirmTime: null,
        adjustGoodsPerson: null,
        adjustGoodsTime: null,
        checkGoodsPerson: null,
        checkGoodsTime: null,
        originGoodsRightCustomer: null,
        goodsRightCustomer: null,
        goodsTransferTimes: null,
        goodsTransferNumber: null,
        goodsTransferPerson: null,
        goodsTransferTime: null,
        goodsTransferAuditPerson: null,
        goodsTransferAuditTime: null,
        goodsTransferIds: null,
        indoorWarehousePrice: null,
        outdoorWarehousePrice: null,
        storageFee: null,
        freeStorage: null,
        overduePriceMode: null,
        overduePrice: null,
        storageDay: null,
        overdueFee: null,
        stackTransferPrice: null,
        stackTransferFee: null,
        warehouseSettlementBillNumber: null,
        warehouseSettlementCustomer: null,
        goodsDamage: null,
        goodsDamagePicture: null,
        goodsRemark: null,
        distributeGoodsStatus: null,
        distributeGoodsCart: null,
        sendGoodsCustomer: null,
        endFlowDirection: null,
        endUnloadPoint: null,
        wayBillNumber: null,
        paymentMode: null,
        freightPriceMode: null,
        freightPrice: null,
        freightAmount: null,
        primage: null,
        freightTotalAmount: null,
        settlementMethod: null,
        settlementPriceMode: null,
        settlementPrice: null,
        settlementAmount: null,
        premiumFreight: null,
        settlementTotalAmount: null,
        freightPaymentBillNumber: null,
        freightSettlementBillNumber: null,
        otherNumber: null,
        threePartyNumber: null,
        createBy: null,
        createTime: null,
      },
      // 表单参数
      form: {},
      // 字典项客户
      customerOptions: [],
      //入库编号
      enterWarehouseNumber: "",
      //计划行
      enterWarehouseRow: [],

    };
  },
  created() {
    this.getList();
    this.getOption();
//    console.log('this.dicts',this.dicts);
//    console.log('this.dict',this.dict);
//    console.log('addgoods, create, ');
  },
  methods: {
    // 窗口初始化方法，nextTick方法可以添加逻辑，如打开窗口时查询数据填充
    init(open, title, enterWarehouseNumber, enterWarehouseRow) {
      this.open = open;
      this.title = title;
      this.enterWarehouseNumber = enterWarehouseNumber;
      this.enterWarehouseRow = enterWarehouseRow;
      //console.log("this.enterWarehouseRow", this.enterWarehouseRow);
      this.$nextTick(() => {
        this.getList();
      });
    },
    /** 查询货物信息列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeProduceDate && '' != this.daterangeProduceDate) {
        this.queryParams.params["beginProduceDate"] = this.daterangeProduceDate[0];
        this.queryParams.params["endProduceDate"] = this.daterangeProduceDate[1];
      }
      if (null != this.daterangeEnterWarehouseTime && '' != this.daterangeEnterWarehouseTime) {
        this.queryParams.params["beginEnterWarehouseTime"] = this.daterangeEnterWarehouseTime[0];
        this.queryParams.params["endEnterWarehouseTime"] = this.daterangeEnterWarehouseTime[1];
      }
      if (null != this.daterangeEnterWarehouseConfirmTime && '' != this.daterangeEnterWarehouseConfirmTime) {
        this.queryParams.params["beginEnterWarehouseConfirmTime"] = this.daterangeEnterWarehouseConfirmTime[0];
        this.queryParams.params["endEnterWarehouseConfirmTime"] = this.daterangeEnterWarehouseConfirmTime[1];
      }
      if (null != this.daterangeExitWarehouseTime && '' != this.daterangeExitWarehouseTime) {
        this.queryParams.params["beginExitWarehouseTime"] = this.daterangeExitWarehouseTime[0];
        this.queryParams.params["endExitWarehouseTime"] = this.daterangeExitWarehouseTime[1];
      }
      if (null != this.daterangeExitWarehouseConfirmTime && '' != this.daterangeExitWarehouseConfirmTime) {
        this.queryParams.params["beginExitWarehouseConfirmTime"] = this.daterangeExitWarehouseConfirmTime[0];
        this.queryParams.params["endExitWarehouseConfirmTime"] = this.daterangeExitWarehouseConfirmTime[1];
      }
      if (null != this.daterangeAdjustGoodsTime && '' != this.daterangeAdjustGoodsTime) {
        this.queryParams.params["beginAdjustGoodsTime"] = this.daterangeAdjustGoodsTime[0];
        this.queryParams.params["endAdjustGoodsTime"] = this.daterangeAdjustGoodsTime[1];
      }
      if (null != this.daterangeCheckGoodsTime && '' != this.daterangeCheckGoodsTime) {
        this.queryParams.params["beginCheckGoodsTime"] = this.daterangeCheckGoodsTime[0];
        this.queryParams.params["endCheckGoodsTime"] = this.daterangeCheckGoodsTime[1];
      }
      if (null != this.daterangeGoodsTransferTime && '' != this.daterangeGoodsTransferTime) {
        this.queryParams.params["beginGoodsTransferTime"] = this.daterangeGoodsTransferTime[0];
        this.queryParams.params["endGoodsTransferTime"] = this.daterangeGoodsTransferTime[1];
      }
      if (null != this.daterangeGoodsTransferAuditTime && '' != this.daterangeGoodsTransferAuditTime) {
        this.queryParams.params["beginGoodsTransferAuditTime"] = this.daterangeGoodsTransferAuditTime[0];
        this.queryParams.params["endGoodsTransferAuditTime"] = this.daterangeGoodsTransferAuditTime[1];
      }
      if (null != this.daterangeCreateTime && '' != this.daterangeCreateTime) {
        this.queryParams.params["beginCreateTime"] = this.daterangeCreateTime[0];
        this.queryParams.params["endCreateTime"] = this.daterangeCreateTime[1];
      }
      listGood(this.queryParams).then(response => {
        this.goodList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
/*      this.form = {
        goodsId: null,
        bundleNumber: null,
        goodsType: null,
        producer: null,
        product: null,
        specification: null,
        steelGrade: null,
        weight: null,
        agreementNumber: null,
        contractNumber: null,
        produceDate: null,
        recordSource: null,
        inventoryStatus: null,
        warehouseType: null,
        logisticsParkName: null,
        warehouseLocateName: null,
        regionLocateName: null,
        goodsLocateName: null,
        layerLocateName: null,
        warehouseTotalLocate: null,
        enterWarehouseNumber: null,
        enterWarehouseCheck: null,
        enterWarehouseCustomer: null,
        enterWarehouseDriver: null,
        enterWarehouseVehicle: null,
        enterWarehousePerson: null,
        enterWarehouseTime: null,
        enterWarehouseConfirmPerson: null,
        enterWarehouseConfirmTime: null,
        exitWarehouseNumber: null,
        exitWarehouseCheck: null,
        exitWarehouseCustomer: null,
        exitWarehouseDriver: null,
        exitWarehouseVehicle: null,
        exitWarehousePerson: null,
        exitWarehouseTime: null,
        exitWarehouseConfirmPerson: null,
        exitWarehouseConfirmTime: null,
        adjustGoodsPerson: null,
        adjustGoodsTime: null,
        checkGoodsPerson: null,
        checkGoodsTime: null,
        originGoodsRightCustomer: null,
        goodsRightCustomer: null,
        goodsTransferTimes: null,
        goodsTransferNumber: null,
        goodsTransferPerson: null,
        goodsTransferTime: null,
        goodsTransferAuditPerson: null,
        goodsTransferAuditTime: null,
        goodsTransferIds: null,
        indoorWarehousePrice: null,
        outdoorWarehousePrice: null,
        storageFee: null,
        freeStorage: null,
        overduePriceMode: null,
        overduePrice: null,
        storageDay: null,
        overdueFee: null,
        stackTransferPrice: null,
        stackTransferFee: null,
        warehouseSettlementBillNumber: null,
        warehouseSettlementCustomer: null,
        goodsDamage: null,
        goodsDamagePicture: null,
        goodsRemark: null,
        distributeGoodsStatus: null,
        distributeGoodsCart: null,
        sendGoodsCustomer: null,
        endFlowDirection: null,
        endUnloadPoint: null,
        wayBillNumber: null,
        paymentMode: null,
        freightPriceMode: null,
        freightPrice: null,
        freightAmount: null,
        primage: null,
        freightTotalAmount: null,
        settlementMethod: null,
        settlementPriceMode: null,
        settlementPrice: null,
        settlementAmount: null,
        premiumFreight: null,
        settlementTotalAmount: null,
        freightPaymentBillNumber: null,
        freightSettlementBillNumber: null,
        otherNumber: null,
        threePartyNumber: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };*/
      //this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      if(isNotNull(this.queryParams.bundleNumber)){
        this.queryParams.bundleNumber = this.queryParams.bundleNumber.replace(/\n/g, ',');
      }
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeProduceDate = [];
      this.daterangeEnterWarehouseTime = [];
      this.daterangeEnterWarehouseConfirmTime = [];
      this.daterangeExitWarehouseTime = [];
      this.daterangeExitWarehouseConfirmTime = [];
      this.daterangeAdjustGoodsTime = [];
      this.daterangeCheckGoodsTime = [];
      this.daterangeGoodsTransferTime = [];
      this.daterangeGoodsTransferAuditTime = [];
      this.daterangeCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.goodsId)
      this.single = selection.length!==1
      this.multiple = !selection.length
//      console.log('this.ids', this.ids);
    },
    getOption() {
      /** 字典项客户*/
      listCustomerOption().then(response => {
        this.customerOptions = response.data;

//        console.log('this.customerOptions',this.customerOptions);
      });
    },
    submitForm() {
//      console.log("this.enterWarehouseNumber = ", this.enterWarehouseNumber);
//      console.log('this.ids', this.ids);
      this.open = false;
      /** 修改*/
      if ((this.ids.length > 0) && isNotNull(this.enterWarehouseNumber)) {
        updateGoodEnterWarehouseNumber(this.ids, this.enterWarehouseNumber).then(response => {
          this.refreshGoodsDetail(this.enterWarehouseNumber);
//          console.log('response.msg', response.msg);
          //calculateGoodTotalWeight(this.wayBill).then(response => {
          //  console.log('response.msg', response.msg);
            this.$parent.getList();
          //});
        });
      }
    }
  }
};
</script>
